<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>活动</title>
    <link href="//res.wx.qq.com/open/libs/weui/1.1.2/weui.min.css" rel="stylesheet">
    <style>
        body {
            max-width: 750px;
            margin: 0 auto;
            background: #f8f8f8;
        }
        pre {
            font-family: "微软雅黑";
            white-space: pre-wrap;
            word-wrap: break-word;
        }
        img {
            width: 100%;
            display: block;
        }

        .pop {
            position: fixed;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            z-index: 1000;
            background: rgba(0, 0, 0, 0.85);
            text-align: center;
            display: none;
        }

        .pop p {
            position: absolute;
            right: 30px;
            top: 30px;
            color: #fff;
        }

        .rule {
            padding: 15px;
        }

        .rule p {
            font-size: 14px;
            margin-top: 10px;
            color: #333;
        }

        h3 {
            text-align: center;
            padding: 20px 0 15px;
            background: #0085ff;
            color: #fff;
        }

        .weui-btn {
            margin: 15px;
            background: #0085ff !important;
        }

        .js-list {
            background: #0085ff;
            padding: 15px;
            border-top: 1px dashed #fff;
            color: #fff;
        }

        .notice {
            font-size: 14px;
            padding: 10px;
        }

        .gzh {
            text-decoration: underline;
        }
    </style>
    <script src="//res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
</head>

<body>
<h3>一键领取饿了么大红包</h3>

<p style="text-align: center; margin-top: 10px;" class="js-score" th:text="'您当前剩余积分为:'+${integration}"></p>
<div id="phone" class="form js-phone">
    <div class="weui-cells__title">请输入您的饿了么账号</div>
    <div class="weui-cells">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" placeholder="11位手机号码" id="tel" maxlength="11" th:value="${phone}">
            </div>
        </div>
    </div>
    <div class="weui-cells__title">选择您要领取的红包类型</div>
    <div style="margin-left: 25px;">
        <pre><input style="margin-top: 20px" name="radio" type="radio" value="7" checked>   通用礼包</pre>
        <pre><input style="margin-top: 20px" name="radio" type="radio" value="5">   每日礼包一</pre>
        <pre><input style="margin-top: 20px" name="radio" type="radio" value="8">   品质35-5</pre>
        <pre><input style="margin-top: 20px" name="radio" type="radio" value="10">   通用35-5</pre>
        <pre><input style="margin-top: 20px" name="radio" type="radio" value="4">   批量礼包</pre>
    </div>
    <a id="start" onclick="lucky()" href="javascript:" class="weui-btn weui-btn_primary js-next1"></a>
</div>
<div id="phone_code" class="form js-code" style="display: none">
    <div class="weui-cells__title">请输入您收到的手机短信验证码</div>
    <div class="weui-cells">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" type="tel" placeholder="短信验证码" id="smsCode" maxlength="6">
            </div>
        </div>
    </div>
    <a onclick="lucky2()" href="javascript:" class="weui-btn weui-btn_primary js-next1"></a>
</div>

<div class="rule" style="font-size: 12px">
    <h4>领取规则：</h4>
    <br/>
    <div th:if="${platform==2}">• 成功领取一次红包消耗20积分</div>
    <div th:if="${platform!=2}">• 成功领取一次红包消耗10积分</div>
    <div>
        <pre>• [通用红包]大概率含有以下红包：</pre>
        <pre>   5元 饿了么通用红包 满¥45可用</pre>
        <pre>   4元 饿了么通用红包 满¥30可用</pre>
        <pre>   9元 星巴克红包 满¥20可用</pre>
        <pre>   另外附赠一些其他红包</pre>
        <pre>• [每日礼包一]一般含有以下4个红包：</pre>
        <pre>   4元 平台通用红包 满¥25/¥30可用</pre>
        <pre>   5元 品质联盟专享红包 满¥25/¥30可用</pre>
        <pre>   5元 下午茶红包 满¥30可用</pre>
        <pre>   6元 夜宵红包 满¥45可用</pre>
        <pre>• [批量礼包]一般含有4～10个红包，品质、通用等随机出现</pre>
        <pre>   至少领取到一个4元的算领取成功</pre>
        <pre>• [品质35-5红包]一般含有2个品质联盟红包,每日可以领取2次</pre>
        <pre>   5元 品质联盟专享红包 满¥35可用</pre>
        <pre>   2元 品质联盟专享红包 满¥10可用</pre>
        <pre>• [通用35-5红包]含有1个平台通用红包</pre>
        <pre>   5元 平台通用红包 满¥35可用</pre>
    </div>
    <div id="apandDiv"></div>
</div>
<input id="platform" type="hidden" th:value="${platform}">
<input id="openId" type="hidden" th:value="${openId}">
<input id="integration" type="hidden" th:value="${integration}">
<input id="recharge_url" type="hidden" th:value="${recharge_url}">
<input id="integral" type="hidden" th:value="${integral}">
</body>
</html>
<script>
    window.onload = function() {
        if($("#platform").val() == 10){
            var apandDiv = document.getElementById("apandDiv");
            apandDiv.innerHTML = "<div>7. 点击加入福利qq群:<a href=\"https://jq.qq.com/?_wv=1027&k=5j8nxpb\">福利群</a></div>\n" +
                "    <div>8. 如遇到问题请<a href=\"https://mp.weixin.qq.com/s/UrWLDhpCOJWtqdhL9c8img\">联系客服</a></div>";
        }
    }

    var phone = null;
    var platform = null;
    var $next1 = $('.js-next1');
    var openId = null;
    var type = null;
    var validateCode = null;
    var validateToken = null;
    var integration = $('#integration').val();
    var integral = 10
    if(platform==2){
        integration=20;
    }
    if(integration<integral){
        $next1.text("积分不足,点击充值...");
    }else{
        $next1.text("领取红包");
    }
    var isclick= true;
    var url = null;

    function lucky(){
        if(integration<integral){
            window.location.href=$('#recharge_url').val();
            return;
        }
        phone = $("#tel").val();
        platform = $("#platform").val();
        openId = $("#openId").val();
        if(phone==null||phone==''||phone.length<11){
            alert("手机号不能为空");
            return;
        }
        type=$("input[name='radio']:checked").val();
        $next1.prop("disabled", true);
        $next1.text("请稍候...");
        if (type == 1 || type == 2) {
            url = "/spellLuck";
        } else if (type == 3) {
            url = "/dayPacket";
        } else if (type == 4) {
            url = "/activePacket";
        } else if (type == 5) {
            url = "/dayPacket2";
        } else if (type == 6) {
            url = "/newActivity";
        } else if (type == 7) {
            url = "/generalLucky";
        } else if (type == 8 || type == 10) {
            url = "/pinzhi";
        }
        if(!isclick){
            return;
        }
            isclick = false;
            $.post(url, {'phone':phone,'platform':platform,'openId':openId,'type':type,'receiveType':1}, function (data) {
                if(data.code==401){
                    document.getElementById("phone").style.display='none';
                    document.getElementById("phone_code").style.display='block';
                    validateToken=data.data;
                    $next1.prop("disabled", false);
                    $next1.text("领取红包");
                    alert("请输入短信验证码");
                    isclick = true;
                }else if(data.code==200){
                    document.getElementById("phone_code").style.display='none';
                    document.getElementById("phone").style.display='block';
                    $next1.prop("disabled", false);
                    $next1.text("领取红包");
                    alert(data.data);
                    isclick = true;
                }else{
                    document.getElementById("phone_code").style.display='none';
                    document.getElementById("phone").style.display='block';
                    $next1.prop("disabled", false);
                    $next1.text("领取红包");
                    alert(data.msg);
                    isclick = true;
                }
            })
    }
    setTimeout(function(){
    }, 300);
    function lucky2(){
        $next1.prop("disabled", true);
        $next1.text("请稍候...");
        validateCode=$('#smsCode').val();
        if (type == 1 || type == 2) {
            url = "/spellLuck";
        } else if (type == 3) {
            url = "/dayPacket";
        } else if (type == 4) {
            url = "/activePacket";
        } else if (type == 5) {
            url = "/dayPacket2";
        } else if (type == 6) {
            url = "/newActivity";
        } else if (type == 7) {
            url = "/generalLucky";
        } else if (type == 8 || type == 10) {
            url = "/pinzhi";
        }

            $.post(url, {'phone':phone,'platform':platform,'openId':openId,'type':type,'validateToken':validateToken,'validateCode':validateCode,'receiveType':2}, function (data) {
                if(data.code==401){
                    document.getElementById("phone").style.display='none';
                    document.getElementById("phone_code").style.display='block';
                    validateToken=data.data;
                    $next1.prop("disabled", false);
                    $next1.text("领取红包");
                    alert("请输入短信验证码")
                }
                else if(data.code==200){
                    document.getElementById("phone_code").style.display='none';
                    document.getElementById("phone").style.display='block';
                    $next1.prop("disabled", false);
                    $next1.text("领取红包");
                    alert(data.data)
                }else{
                    document.getElementById("phone_code").style.display='none';
                    document.getElementById("phone").style.display='block';
                    $next1.prop("disabled", false);
                    $next1.text("领取红包");
                    alert(data.msg)
                }

            })
            setTimeout(function(){
            }, 1000);
    }
</script>
